import { observable, action } from "mobx";
import resource from "@/utils/resource";
import API from "@/utils/monitorwarning";
class AppStore {
    @observable resultData = [];
    @observable curTab = "follow";
    @observable type = "APP";
    @observable curItem = {};
    @observable curOpenItem = {};

    @observable status = {};
    @observable keywords = "";

    @action.bound
    init = type => {
        console.log("init data");
        this.type = type || this.type;

        this.getAppResultList();
    };

    @action.bound
    getAppResultList() {
        const url = this.type === "APP" ? API.monitorwarningAPP : API.monitorwarningPeople;
        // this.resultData = [];
        resource.get(url, { type: this.curTab, keywords: this.keywords }).then(res => {
            this.resultData = res.list;
        });
    }

    @action.bound
    changeTab = item => {
        this.curTab = item;
        // this.init();
        this.getAppResultList();
    };

    @action.bound
    selectCurItem = item => {
        this.curItem = item;
        // 左侧选中app，更新右侧卡片数据
        // this.getRightCardResultList();
    };

    @action.bound
    selectCurOpenItem = item => {
        this.curOpenItem = item;
    };

    @action.bound
    changeCurOpenItem = item => {
        this.curOpenItem = {
            ...this.curOpenItem,
            ...item
        };
    };

    @action.bound
    delete = item => {
        console.log("delete one item", item);
        this.getAppResultList();
    };

    @action.bound
    addControl = callBack => {
        // 调用后台接口

        // 加入管控,刷新数据
        this.getAppResultList();

        callBack(); // 关闭弹窗
    };

    @action.bound
    updateStatus = newStatus => {
        this.status = {
            ...this.status,
            ...newStatus
        };
    };

    @action.bound
    setKeywords = key => {
        this.keywords = key;
    };
}

export default new AppStore();
